#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int maxFreq(string s, int maxLetters, int minSize, int maxSize) {
        unordered_map<char, int> cur;
        unordered_map<string, int> count;
        int n = s.size();
        for (int i = 0; i < minSize; i++)
            cur[s[i]]++;
        int ret = 0;
        if (cur.size() <= maxLetters)
            ret = max(ret, ++count[s.substr(0, minSize)]);

        for (int i = minSize; i < n; i++)
        {
            if (--cur[s[i - minSize]] == 0)
                cur.erase(s[i - minSize]);
            cur[s[i]]++;

            if (cur.size() <= maxLetters)
                ret = max(ret, ++count[s.substr(i - minSize + 1, minSize)]);
        }
        return ret;
    }
};